#ifndef E3D_VECTOR2_HPP
#define E3D_VECTOR2_HPP

#ifndef __cplusplus
#error "C++ required"
#endif

namespace e3d {

	template <typename real>
	class Vector2 {
	public:
		typedef real_traits<real> traits;
		typedef Vector2<real> vector_type;
	public:
		union {
			real v[2];
			struct {
				real x;
				real y;
			};
		};

		Vector2(real x_ = traits::zero, real y_ = traits::zero) : x(x_), y(y_) {}
		Vector2(vector_type const & o) : x(o.x), y(o.y) {}

		vector_type & operator += (const vector_type & o) {
			x += o.x;
			y += o.y;
			return *this;
		}
		vector_type & operator -= (const vector_type & o) {
			x -= o.x;
			y -= o.y;
			return *this;
		}
		template <typename real2>
		vector_type & operator *= (const real2 & o) {
			x *= o;
			y *= o;
			return *this;
		}
		template <typename real2>
		vector_type & operator /= (const real2 & o) {
			x /= o;
			y /= o;
			return *this;
		}
	};

	template <typename real>
	bool operator==(const Vector2<real> & a, const Vector2<real> & b) {
		return real_traits<real>::equals(a.x, b.x) &&
			real_traits<real>::equals(a.y, b.y);
	}

	template <typename real>
	Vector2<real> operator+(const Vector2<real> & a, const Vector2<real> & b) {
		Vector2<real> r(a.x + b.x, a.y + b.y);
		return r;
	}

	template <typename real>
	Vector2<real> operator-(const Vector2<real> & a, const Vector2<real> & b) {
		Vector2<real> r(a.x - b.x, a.y - b.y);
		return r;
	}

}

#endif
